home *** CD-ROM | disk | FTP | other *** search
/ Aminet 21 / Aminet 21 (1997)(GTI - Schatztruhe)[!][Oct 1997].iso / Aminet / dev / misc / gms_dev.lha / GMS / Source / Asm / System / StartGMS.s < prev   
Encoding:
Text File  |  1997-07-08  |  6.8 KB  |  242 lines

  1. ;START GMS
  2. ;---------
  3. ;Usage:   StartGMS <TaskFile>
  4. ;Author:  Paul Manias
  5. ;Version: V0.2
  6. ;Date:    30/5/97
  7. ;Docs:    This program is intended to allow multi-platform capabilities by
  8. ;      doing things like opening GMS for the task.  For example the
  9. ;      following code would not work on a Mac even if it is 68000 code:
  10. ;
  11. ;      move.l $4.w,a6
  12. ;      ...
  13. ;      CALL   OpenLibrary
  14. ;
  15. ;      To fix this problem we put this machine-specific code in a task
  16. ;      launcher (StartGMS) and pass the GMSBase onto the task.  Alakazam,
  17. ;      multiple platform capabilities!
  18. ;
  19. ;PROBLEMS: Programs written in E cannot cope with this as far as I know :-(.
  20.  
  21.     INCDIR    "INCLUDES:"
  22.     INCLUDE    "exec/exec_lib.i"
  23.     INCLUDE    "dos/dos_lib.i"
  24.     INCLUDE    "exec/libraries.i"
  25.     INCLUDE    "games/games_lib.i"
  26.  
  27. CALL    MACRO
  28.     jsr    _LVO\1(a6)
  29.     ENDM
  30.  
  31.     SECTION    "StartGMS",CODE
  32.  
  33. ;===================================================================================;
  34. ;                                INITIALISE PROGRAM
  35. ;===================================================================================;
  36. ;Requires: a0 = Pointer to file to load???
  37.  
  38. Start:    MOVEM.L    A0-A6/D0-D7,-(SP)
  39.     move.l    a0,CommandLine
  40.     move.l    d0,AmtCommands
  41.  
  42.     move.l    ($4).w,a6
  43.     lea    DOSName(pc),a1
  44.     moveq    #$00,d0
  45.     CALL    OpenLibrary
  46.     move.l    d0,DOSBase
  47.     beq.s    .Error_DOS
  48.  
  49.     lea    GMSName(pc),a1
  50.     moveq    #$00,d0
  51.     CALL    OpenLibrary
  52.     move.l    d0,GMSBase
  53.     beq.s    .Error_GMS
  54.  
  55.     cmp.l    #1,AmtCommands
  56.     ble.s    .ReturnToDOS
  57.     move.l    CommandLine(pc),a0
  58.     cmp.b    #"?",(a0)
  59.     bne.s    .go
  60.     bsr.s    Usage
  61.     bra.s    .ReturnToDOS
  62.  
  63. .go    bsr.s    ParseArguments
  64.     tst.l    d0
  65.     bne.s    .ReturnToDOS
  66.     bsr    Launch
  67.     bsr    FreeArguments
  68.  
  69. .ReturnToDOS
  70. .Error_GMS
  71.     move.l    ($4).w,a6
  72.     move.l    DOSBase(pc),a1
  73.     CALL    CloseLibrary
  74. .Error_DOS
  75.     MOVEM.L    (SP)+,A0-A6/D0-D7
  76.     moveq    #$00,d0
  77.     rts
  78.  
  79. ;===================================================================================;
  80. ;                             PRINT USAGE INFORMATION
  81. ;===================================================================================;
  82.  
  83. Usage:    move.l    DOSBase(pc),a6
  84.     CALL    Output
  85.     move.l    d0,d1    ;d1 = File handle to write out to.
  86.     move.l    #TXT_Usage,d2    ;d2 = Pointer to buffered text.
  87.     move.l    #TXT_UsageSize,d3    ;d3 = Size of text.
  88.     CALL    Write
  89.     rts
  90.  
  91. ;===================================================================================;
  92. ;                                 PARSE ARGUMENTS
  93. ;===================================================================================;
  94. ;Template is: StartGMS <TaskFile> [PREFS <Name>] <Arg1> <Arg2> ...
  95.  
  96. ParseArguments:
  97.     move.l    CommandLine(pc),a0    ;a0 = Pointer to first char of <TaskFile>.
  98.     moveq    #$00,d0    ;d0 = Byte count of file name.
  99. .loop    cmp.b    #10,(a0)    ;a0 = Check for return key.
  100.     beq.s    .key_return    ;>> = Return key found.
  101.     cmp.b    #' ',(a0)    ;a0 = Check for space key.
  102.     beq.s    .key_space    ;>> = Return key found.
  103.     addq.l    #1,d0    ;d0 = ++1
  104.     addq.w    #1,a0    ;a0 = ++1
  105.     bra.s    .loop    ;>> = Keep looping till we find the end.
  106.  
  107. .key_return
  108.     move.b    #' ',(a0)    ;a0 = Replace return key with a space.
  109. .key_space
  110.     addq.l    #1,a0    ;a0 = ++1
  111.     move.l    a0,TaskArgs    ;MA = Save pointer to GMS task args.
  112.     move.l    ($4).w,a6    ;a6 = ExecBase
  113.     addq.l    #1,d0    ;d0 = (MemSize)+1 [For null termination]
  114.     move.l    d0,sizeTaskFile    ;MA = Make a note of the size allocated.
  115.     moveq    #$0,d1    ;d1 = MemType
  116.     CALL    AllocMem    ;>> = AllocMem(Size:d0,Type:d1)
  117.     move.l    d0,TaskFile    ;MA = Pointer to file memory.
  118.     beq.s    .Error_Memory    ;>> = Memory error.
  119.  
  120.     move.l    CommandLine(pc),a0    ;a0 = Command Line source.
  121.     move.l    TaskFile(pc),a1    ;a1 = FileName destination.
  122. .cloop    cmp.b    #" ",(a0)    ;a0 = Check for space.
  123.     beq.s    .done    ;>> = Got it.
  124.     move.b    (a0)+,(a1)+    ;a1 = Copy Character++
  125.     bra.s    .cloop    ;>> = Keep looping.
  126.  
  127. .done    clr.b    (a1)+
  128.     moveq    #$00,d0    ;d0 = No errors.
  129.     rts
  130.  
  131. .Error_Memory
  132.     moveq    #$01,d0    ;d0 = Memory error.
  133.     rts
  134.  
  135. FreeArguments:
  136.     move.l    ($4).w,a6    ;a6 = ExecBase.
  137.     move.l    TaskFile(pc),a1    ;a1 = Pointer to allocated block.
  138.     move.l    sizeTaskFile(pc),d0    ;d0 = Size of allocated block.
  139.     CALL    FreeMem    ;>> = Free it.
  140.     rts
  141.  
  142. ;===================================================================================;
  143. ;                                LAUNCH GMS PROGRAM
  144. ;===================================================================================;
  145. ;Load the program in with LoadSeg() and then run it (remembering to pass the
  146. ;necessary variables).  On other machines this part will have to be modified to
  147. ;recognise and load in Amiga formatted file hunks.
  148. ;
  149. ;Sends: a0 = Command Line Parameters
  150. ;    a1 = GMSBase
  151. ;    a2 = Pointer to address of program.
  152. ;    d0 = "GMSP" Identification.
  153. ;    d1 = Amount of commands on line.
  154. ;    d2 = (Version<<16)|(Revision)
  155.  
  156. Launch:    move.l    DOSBase(pc),a6    ;a6 = DOS Base.
  157.     move.l    TaskFile(pc),d1    ;d1 = Pointer to file name.
  158.     CALL    LoadSeg    ;>> = Go and load the executable.
  159.     move.l    d0,Segment    ;MA = Store pointer to segment.
  160.     beq.s    .Error_Segment    ;>> = Error loading file :-(
  161.  
  162.     ;Initialise self-destruct sequence.
  163.  
  164.     move.l    GMSBase(pc),a6    ;a6 = GMSBase.
  165.     lea    .exit(pc),a0    ;a0 = Pointer to SelfDestruct() cleanup.
  166.     move.l    a7,a1    ;a1 = Stack pointer.
  167.     CALL    InitDestruct    ;>> = Initialise the call.
  168.  
  169.     ;Setup parameters here.
  170.  
  171.     move.l    Segment(pc),d0    ;d0 = BCPL pointer to segment.
  172.     add.l    d0,d0    ;d0 = *2
  173.     add.l    d0,d0    ;d0 = *4
  174.     move.l    d0,a2    ;a2 = Pointer to start of seglist.
  175.     move.l    GMSBase(pc),a1    ;a1 = Pointer to GMSBase.
  176.     move.l    #"GMSP",d0    ;d0 = "GMSP"
  177.  
  178.     move.w    LIB_VERSION(a1),d2    ;d2 = Version
  179.     swap    d2    ;d2 = (Version)<<16
  180.     move.w    LIB_REVISION(a1),d2    ;d2 = (Version<<16)|(Revision)
  181.  
  182.     sub.l    a3,a3    ;Clear all other registers before
  183.     sub.l    a4,a4    ;launching the task.
  184.     sub.l    a5,a5
  185.     sub.l    a6,a6
  186.     moveq    #$00,d2
  187.     moveq    #$00,d3
  188.     moveq    #$00,d4
  189.     moveq    #$00,d5
  190.     moveq    #$00,d6
  191.     moveq    #$00,d7
  192.     jsr    4(a2)    ;>> = Start the GMS program.
  193.  
  194. .exit    move.l    GMSBase(pc),a6
  195.     CALL    CloseGMS
  196.  
  197.     move.l    DOSBase(pc),a6    ;a6 = DOS Base.
  198.     move.l    Segment(pc),d1    ;d1 = BCPL segment pointer.
  199.     CALL    UnLoadSeg    ;>> = Unload the program.
  200. .Error_Segment
  201.     rts
  202.  
  203. ;===================================================================================;
  204. ;                                       DATA
  205. ;===================================================================================;
  206.  
  207. GMSName: dc.b    "GMS:libs/dpkernal.library",0
  208.      even
  209. DOSName: dc.b    "dos.library",0
  210.      even
  211.  
  212. GMSBase:  dc.l    0    ;Pointer to GMSBase.
  213. DOSBase:  dc.l    0
  214.  
  215. TaskFile:    dc.l  0    ;Name of file to load.
  216. sizeTaskFile dc.l  0    ;Size of allocated memory block.
  217. Segment:     dc.l  0    ;Pointer to segment of loaded file.
  218. CommandLine  dc.l  0    ;Pointer to first command line argument.
  219. AmtCommands: dc.l  0    ;Amount of arguments on command line.
  220. TaskArgs:    dc.l  0    ;Arguments for the GMS Task.
  221.  
  222. TXT_Usage:
  223.  dc.b    10
  224.  dc.b    "STARTGMS",10
  225.  dc.b    "--------",10
  226.  dc.b    "This program will launch GMS tasks for you, and in future will",10
  227.  dc.b    "be required for setting up GMS games that have been compiled on other",10
  228.  dc.b    "platforms.",10
  229.  dc.b    10
  230.  dc.b    "To use it, just type:",10
  231.  dc.b    10
  232.  dc.b    "  1> StartGMS <FileName> <Arg1> <Arg2> <Arg3> ...",10
  233.  dc.b    10
  234.  dc.b    "Example:",10
  235.  dc.b    10
  236.  dc.b    "  1> StartGMS GMS:demos/Redimension",10
  237.  dc.b    10
  238.  dc.b    0
  239.  
  240. TXT_UsageSize = *-TXT_Usage
  241.  
  242.